<template>
    <div class="e-form">
        <BillTop :title="$route.meta.title" @cancel="handleClose"></BillTop>
        <div class="tabs warningTabs"></div>
        <div class="tabs" v-if="Object.keys(formData).length != 0">
            <el-tabs tab-position="left" v-model="tabsName" @tab-click="onChangeTab">
                <el-tab-pane
                    label="基本信息"
                    name="baseInfo"
                    :disabled="clickTabFlag"
                ></el-tab-pane>
                <el-tab-pane
                    label="中标候选人"
                    name="bidWinMan"
                    :disabled="clickTabFlag"
                ></el-tab-pane>
                <el-tab-pane label="附件信息" name="attach" :disabled="clickTabFlag"></el-tab-pane>
                <el-tab-pane
                    label="审核历史"
                    name="auditHistory"
                    :disabled="clickTabFlag"
                ></el-tab-pane>
                <div>
                    <div id="baseInfoCon" class="con">
                        <div class="tabs-title" id="baseInfo">基本信息</div>
                        <div style="width: 100%" class="form">
                            <el-form
                                :model="formData"
                                label-width="170px"
                                :rules="rules"
                                ref="ruleForm"
                                v-if="auditState.canModify"
                            >
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="招标项目名称：">
                                            <span>{{ formData.projectName }}</span>
                                            <ComShowBiddingButton
                                                :tenderId="tenderId"
                                                mod="equipHire"
                                            />
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="招标编号：">
                                            <div style="display: flex">
                                                <el-input
                                                    v-model="formData.tenderApplyNo"
                                                    disabled
                                                ></el-input>
                                                <!-- <ComShowBiddingButton
                                                    :tenderId="tenderId"
                                                    mod="equipHire"
                                                /> -->
                                            </div>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="招标方式：">
                                            <span v-if="formData.tenderForm">{{
                                                formData.tenderForm | tenderForm(this)
                                            }}</span>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="招标类型：">
                                            <span>{{
                                                formData.tenderClass | tenderClass(this)
                                            }}</span>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="招标人：">
                                            <span>{{ formData.founderName }}</span>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="状态：">
                                            <span>{{ formData.state | state(this) }}</span>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <ComNullify :formData="formData" />
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="登记日期：">
                                            <el-date-picker
                                                v-model="formData.reportTime"
                                                type="date"
                                                placeholder="选择日期"
                                            >
                                            </el-date-picker>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-form-item label="评标记录：" prop="evaluationRecord">
                                        <el-input
                                            type="textarea"
                                            :rows="2"
                                            placeholder="请输入内容"
                                            v-model="formData.evaluationRecord"
                                            style="margin-right: 110px"
                                        >
                                        </el-input>
                                    </el-form-item>
                                </el-row>
                                <el-row>
                                    <el-form-item label="备注：">
                                        <el-input
                                            type="textarea"
                                            :rows="2"
                                            placeholder="请输入内容"
                                            v-model="formData.remarks"
                                            style="margin-right: 110px"
                                        >
                                        </el-input>
                                    </el-form-item>
                                </el-row>
                            </el-form>
                            <el-form
                                :model="formData"
                                label-width="170px"
                                :rules="rules"
                                ref="ruleForm"
                                v-else
                            >
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="招标项目名称：">
                                            <span>{{ formData.projectName }}</span>
                                            <ComShowBiddingButton
                                                :tenderId="tenderId"
                                                mod="equipHire"
                                            />
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="招标编号：">
                                            <div style="display: flex">
                                                <el-input
                                                    v-model="formData.tenderApplyNo"
                                                    disabled
                                                ></el-input>
                                                <!-- <ComShowBiddingButton
                                                    :tenderId="tenderId"
                                                    mod="equipHire"
                                                /> -->
                                            </div>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="招标方式：">
                                            <span v-if="formData.tenderForm">{{
                                                formData.tenderForm | tenderForm(this)
                                            }}</span>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="招标类型：">
                                            <span>{{
                                                formData.tenderClass | tenderClass(this)
                                            }}</span>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="招标人：">
                                            <span>{{ formData.founderName }}</span>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="状态：">
                                            <span>{{ formData.state | state(this) }}</span>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <ComNullify :formData="formData" />
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="登记日期：">
                                            <span>{{ formData.reportTime }}</span>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-form-item label="评标记录：" prop="evaluationRecord">
                                        <span>{{ formData.evaluationRecord }}</span>
                                    </el-form-item>
                                </el-row>
                                <el-row>
                                    <el-form-item label="备注：">
                                        <span>{{ formData.remarks }}</span>
                                    </el-form-item>
                                </el-row>
                            </el-form>
                        </div>
                    </div>

                    <div id="bidWinManCon" class="con">
                        <div class="tabs-title" id="bidWinMan">中标单位</div>
                        <el-button
                            class="btn-blue"
                            style="margin-bottom: 5px"
                            @click="ContractQuery"
                            >合同签订情况查询</el-button
                        >
                        <div class="ruleMessage" v-if="ruleMessage">
                            {{ ruleMessage }}
                        </div>
                        <div class="e-table">
                            <el-table
                                :data="candidateList"
                                border
                                :cell-class-name="cellClsNm"
                                :key="candidateListKey"
                                v-if="auditState.canModify"
                                :max-height="$store.state.tableHeight"
            ref="table"
            v-sortTable="{ tableData: tableData, _this: this, ref: 'table' }"
                            >
                                <el-table-column
                                    show-overflow-tooltip
                                    prop="packageNo"
                                    label="包件编号"
                                    width="200"
                                    class-name="blue-column"
                                >
                                </el-table-column>
                                <el-table-column
                                    show-overflow-tooltip
                                    prop="packageName"
                                    label="包件名称"
                                    width="200"
                                >
                                </el-table-column>
                                <!-- <el-table-column
                                    show-overflow-tooltip
                                    prop="tenderType"
                                    label="招标类型"
                                    width="200"
                                    :formatter="formatter"
                                >
                                </el-table-column> -->
                                <!-- <el-table-column
                                    show-overflow-tooltip
                                    prop="projectOverview"
                                    label="工程概况"
                                    width="200"
                                >
                                </el-table-column> -->
                                <el-table-column
                                    show-overflow-tooltip
                                    prop="isFail"
                                    label="是否流标"
                                    width="100"
                                >
                                    <template slot-scope="{ row }">
                                        <el-checkbox
                                            v-model="row.isFail"
                                            :true-label="1"
                                            :false-label="0"
                                            @change="isFailChange(row)"
                                        ></el-checkbox>
                                    </template>
                                </el-table-column>
                                <el-table-column
                                    show-overflow-tooltip
                                    prop="threeCandidate"
                                    label="中标单位"
                                    width="200"
                                >
                                    <template slot-scope="{ row, $index }">
                                        <el-select
                                            v-model="row.threeCandidate"
                                            filterable
                                            placeholder="请选择"
                                            @change="
                                                selectChange(row, row.threeCandidate, 3, $index)
                                            "
                                            :disabled="row.isFail === 1"
                                        >
                                            <el-option
                                                v-for="(item, index) in candidateListOption[$index]"
                                                :key="index"
                                                :label="item.candidateName"
                                                :value="item.candidateName"
                                            >
                                            </el-option>
                                        </el-select>
                                    </template>
                                </el-table-column>
                                <el-table-column
                                    show-overflow-tooltip
                                    prop="threeAmount"
                                    label="投标不含税金额（元）"
                                    width="200"
                                >
                                    <template slot-scope="{ row }">
                                        <el-input
                                            v-model="row.threeAmount"
                                            placeholder="请输入内容"
                                            v-enterJustFloat="{
                                                set: row,
                                                key: 'threeAmount'
                                            }"
                                            :disabled="row.isFail === 1"
                                            @blur="inputblur(row, 'threeAmount')"
                                        ></el-input>
                                    </template>
                                </el-table-column>
                                <el-table-column
                                    show-overflow-tooltip
                                    prop="threeGrade"
                                    label="综合得分或价格（元）"
                                    width="200"
                                >
                                    <template slot-scope="{ row }">
                                        <el-input
                                            v-model="row.threeGrade"
                                            placeholder="请输入内容"
                                            v-enterJustFloat="{
                                                set: row,
                                                key: 'threeGrade'
                                            }"
                                            :disabled="row.isFail === 1"
                                            @blur="inputblur(row, 'threeGrade')"
                                        ></el-input>
                                    </template>
                                </el-table-column>
                                <el-table-column
                                    show-overflow-tooltip
                                    prop="firstCandidate"
                                    label="第一单位"
                                    width="200"
                                >
                                    <template slot-scope="{ row, $index }">
                                        <el-select
                                            v-model="row.firstCandidate"
                                            filterable
                                            placeholder="请选择"
                                            @change="
                                                selectChange(row, row.firstCandidate, 1, $index)
                                            "
                                            :disabled="row.isFail === 1"
                                        >
                                            <el-option
                                                v-for="(item, index) in candidateListOption[$index]"
                                                :key="index"
                                                :label="item.candidateName"
                                                :value="item.candidateName"
                                            >
                                            </el-option>
                                        </el-select>
                                    </template>
                                </el-table-column>
                                <el-table-column
                                    show-overflow-tooltip
                                    prop="firstAmount"
                                    label="投标不含税金额（元）"
                                    width="200"
                                >
                                    <template slot-scope="{ row }">
                                        <el-input
                                            v-model="row.firstAmount"
                                            placeholder="请输入内容"
                                            v-enterJustFloat="{
                                                set: row,
                                                key: 'firstAmount'
                                            }"
                                            :disabled="row.isFail === 1"
                                            @blur="inputblur(row, 'firstAmount')"
                                        ></el-input>
                                    </template>
                                </el-table-column>
                                <el-table-column
                                    show-overflow-tooltip
                                    prop="firstGrade"
                                    label="综合得分或价格（元）"
                                    width="200"
                                >
                                    <template slot-scope="{ row }">
                                        <el-input
                                            v-model="row.firstGrade"
                                            placeholder="请输入内容"
                                            v-enterJustFloat="{
                                                set: row,
                                                key: 'firstGrade'
                                            }"
                                            :disabled="row.isFail === 1"
                                            @blur="inputblur(row, 'firstGrade')"
                                        ></el-input>
                                    </template>
                                </el-table-column>
                                <el-table-column
                                    show-overflow-tooltip
                                    prop="twoCandidate"
                                    label="第二单位"
                                    width="200"
                                >
                                    <template slot-scope="{ row, $index }">
                                        <el-select
                                            v-model="row.twoCandidate"
                                            filterable
                                            placeholder="请选择"
                                            @change="selectChange(row, row.twoCandidate, 2, $index)"
                                            :disabled="row.isFail === 1"
                                        >
                                            <el-option
                                                v-for="(item, index) in candidateListOption[$index]"
                                                :key="index"
                                                :label="item.candidateName"
                                                :value="item.candidateName"
                                            >
                                            </el-option>
                                        </el-select>
                                    </template>
                                </el-table-column>
                                <el-table-column
                                    show-overflow-tooltip
                                    prop="twoAmount"
                                    label="投标不含税金额（元）"
                                    width="200"
                                >
                                    <template slot-scope="{ row }">
                                        <el-input
                                            v-model="row.twoAmount"
                                            placeholder="请输入内容"
                                            v-enterJustFloat="{
                                                set: row,
                                                key: 'twoAmount'
                                            }"
                                            :disabled="row.isFail === 1"
                                            @blur="inputblur(row, 'twoAmount')"
                                        ></el-input>
                                    </template>
                                </el-table-column>
                                <el-table-column
                                    show-overflow-tooltip
                                    prop="twoGrade"
                                    label="综合得分或价格（元）"
                                    width="200"
                                >
                                    <template slot-scope="{ row }">
                                        <el-input
                                            v-model="row.twoGrade"
                                            placeholder="请输入内容"
                                            v-enterJustFloat="{
                                                set: row,
                                                key: 'twoGrade'
                                            }"
                                            :disabled="row.isFail === 1"
                                            @blur="inputblur(row, 'twoGrade')"
                                        ></el-input>
                                    </template>
                                </el-table-column>
                                <el-table-column
                                    show-overflow-tooltip
                                    prop="subordinateReferenceOrgName"
                                    label="下级引用机构"
                                    width="200"
                                >
                                    <template slot-scope="{ row }">
                                        <ComInputSelectUnit
                                            :orgName.sync="row.subordinateReferenceOrgName"
                                            :orgId.sync="row.subordinateReferenceOrgId"
                                            :SelectedIDs="
                                                row.subordinateReferenceOrgId !== '' &&
                                                row.subordinateReferenceOrgId !== null
                                                    ? [row.subordinateReferenceOrgId]
                                                    : []
                                            "
                                        />
                                    </template>
                                </el-table-column>
                            </el-table>
                            <el-table
                                :data="candidateList"
                                border
                                :cell-class-name="cellClsNm"
                                :key="candidateListKey"
                                v-else
                                :max-height="$store.state.tableHeight"
            ref="table"
            v-sortTable="{ tableData: tableData, _this: this, ref: 'table' }"
                            >
                                <el-table-column
                                    show-overflow-tooltip
                                    prop="packageNo"
                                    label="包件编号"
                                    width="200"
                                    class-name="blue-column"
                                >
                                </el-table-column>
                                <el-table-column
                                    show-overflow-tooltip
                                    prop="packageName"
                                    label="包件名称"
                                    width="200"
                                >
                                </el-table-column>
                                <!-- <el-table-column
                                    show-overflow-tooltip
                                    prop="tenderType"
                                    label="招标类型"
                                    width="200"
                                    :formatter="formatter"
                                >
                                </el-table-column> -->
                                <!-- <el-table-column
                                    show-overflow-tooltip
                                    prop="projectOverview"
                                    label="工程概况"
                                    width="200"
                                >
                                </el-table-column> -->
                                <el-table-column
                                    show-overflow-tooltip
                                    prop="isFail"
                                    label="是否流标"
                                    width="100"
                                >
                                    <template slot-scope="{ row }">
                                        <el-checkbox
                                            v-model="row.isFail"
                                            :true-label="1"
                                            :false-label="0"
                                            @change="isFailChange(row)"
                                            disabled
                                        ></el-checkbox>
                                    </template>
                                </el-table-column>
                                <el-table-column
                                    show-overflow-tooltip
                                    prop="threeCandidate"
                                    label="中标单位"
                                    width="200"
                                >
                                    <template slot-scope="{ row, $index }">
                                        <el-select
                                            v-model="row.threeCandidate"
                                            filterable
                                            placeholder="请选择"
                                            @change="
                                                selectChange(row, row.threeCandidate, 3, $index)
                                            "
                                            disabled
                                        >
                                            <el-option
                                                v-for="(item, index) in candidateListOption[$index]"
                                                :key="index"
                                                :label="item.candidateName"
                                                :value="item.candidateName"
                                            >
                                            </el-option>
                                        </el-select>
                                    </template>
                                </el-table-column>
                                <el-table-column
                                    show-overflow-tooltip
                                    prop="threeAmount"
                                    label="投标不含税金额（元）"
                                    width="200"
                                >
                                    <template slot-scope="{ row }">
                                        <el-input
                                            v-model="row.threeAmount"
                                            placeholder="请输入内容"
                                            v-enterJustFloat="{
                                                set: row,
                                                key: 'threeAmount'
                                            }"
                                            disabled
                                        ></el-input>
                                    </template>
                                </el-table-column>
                                <el-table-column
                                    show-overflow-tooltip
                                    prop="threeGrade"
                                    label="综合得分或价格（元）"
                                    width="200"
                                >
                                    <template slot-scope="{ row }">
                                        <el-input
                                            v-model="row.threeGrade"
                                            placeholder="请输入内容"
                                            v-enterJustFloat="{
                                                set: row,
                                                key: 'threeGrade'
                                            }"
                                            disabled
                                        ></el-input>
                                    </template>
                                </el-table-column>
                                <el-table-column
                                    show-overflow-tooltip
                                    prop="firstCandidate"
                                    label="第一单位"
                                    width="200"
                                >
                                    <template slot-scope="{ row, $index }">
                                        <el-select
                                            v-model="row.firstCandidate"
                                            filterable
                                            placeholder="请选择"
                                            @change="
                                                selectChange(row, row.firstCandidate, 1, $index)
                                            "
                                            disabled
                                        >
                                            <el-option
                                                v-for="(item, index) in candidateListOption[$index]"
                                                :key="index"
                                                :label="item.candidateName"
                                                :value="item.candidateName"
                                            >
                                            </el-option>
                                        </el-select>
                                    </template>
                                </el-table-column>
                                <el-table-column
                                    show-overflow-tooltip
                                    prop="firstAmount"
                                    label="投标不含税金额（元）"
                                    width="200"
                                >
                                    <template slot-scope="{ row }">
                                        <el-input
                                            v-model="row.firstAmount"
                                            placeholder="请输入内容"
                                            v-enterJustFloat="{
                                                set: row,
                                                key: 'firstAmount'
                                            }"
                                            disabled
                                        ></el-input>
                                    </template>
                                </el-table-column>
                                <el-table-column
                                    show-overflow-tooltip
                                    prop="firstGrade"
                                    label="综合得分或价格（元）"
                                    width="200"
                                >
                                    <template slot-scope="{ row }">
                                        <el-input
                                            v-model="row.firstGrade"
                                            placeholder="请输入内容"
                                            v-enterJustFloat="{
                                                set: row,
                                                key: 'firstGrade'
                                            }"
                                            disabled
                                        ></el-input>
                                    </template>
                                </el-table-column>
                                <el-table-column
                                    show-overflow-tooltip
                                    prop="twoCandidate"
                                    label="第二单位"
                                    width="200"
                                >
                                    <template slot-scope="{ row, $index }">
                                        <el-select
                                            v-model="row.twoCandidate"
                                            filterable
                                            placeholder="请选择"
                                            @change="selectChange(row, row.twoCandidate, 2, $index)"
                                            disabled
                                        >
                                            <el-option
                                                v-for="(item, index) in candidateListOption[$index]"
                                                :key="index"
                                                :label="item.candidateName"
                                                :value="item.candidateName"
                                            >
                                            </el-option>
                                        </el-select>
                                    </template>
                                </el-table-column>
                                <el-table-column
                                    show-overflow-tooltip
                                    prop="twoAmount"
                                    label="投标不含税金额（元）"
                                    width="200"
                                >
                                    <template slot-scope="{ row }">
                                        <el-input
                                            v-model="row.twoAmount"
                                            placeholder="请输入内容"
                                            v-enterJustFloat="{
                                                set: row,
                                                key: 'twoAmount'
                                            }"
                                            disabled
                                        ></el-input>
                                    </template>
                                </el-table-column>
                                <el-table-column
                                    show-overflow-tooltip
                                    prop="twoGrade"
                                    label="综合得分或价格（元）"
                                    width="200"
                                >
                                    <template slot-scope="{ row }">
                                        <el-input
                                            v-model="row.twoGrade"
                                            placeholder="请输入内容"
                                            v-enterJustFloat="{
                                                set: row,
                                                key: 'twoGrade'
                                            }"
                                            disabled
                                        ></el-input>
                                    </template>
                                </el-table-column>
                                <el-table-column
                                    show-overflow-tooltip
                                    prop="subordinateReferenceOrgName"
                                    label="下级引用机构"
                                    width="200"
                                >
                                    <template slot-scope="{ row }">
                                        <ComInputSelectUnit
                                            :orgName.sync="row.subordinateReferenceOrgName"
                                            :orgId.sync="row.subordinateReferenceOrgId"
                                            :SelectedIDs="
                                                row.subordinateReferenceOrgId !== '' &&
                                                row.subordinateReferenceOrgId !== null
                                                    ? [row.subordinateReferenceOrgId]
                                                    : []
                                            "
                                            :edit="false"
                                        />
                                    </template>
                                </el-table-column>
                            </el-table>
                        </div>
                    </div>

                    <div id="attachCon" class="con">
                        <div class="tabs-title" id="attach">附件信息</div>
                        <ComAttachIndex
                            bucketName="tender"
                            :relationId="billId"
                            ref="ComAttachIndex"
                            :isView="
                                (auditState.canAudit === false && auditState.canModify === false) ||
                                Object.keys(auditState).length === 0
                            "
                            v-if="Object.keys(auditState).length !== 0"
                        />
                    </div>

                    <div id="auditHistoryCon" class="con">
                        <div class="tabs-title" id="auditHistory">审核历史</div>
                        <ComExaHistory :billType="60295" ref="ComExaHistory" />
                    </div>
                </div>
            </el-tabs>
        </div>
        <div class="buttons">
            <!-- <ComBidButtons
                :formData="formData"
                api="equipmentLeasing"
                ref="ComBidButtons"
                :releaseState="false"
                releaseType="3"
                :onlyRelease="true"
            /> -->
            <ComExaButtons
                :auditState="auditState"
                @exas="exas"
                :routeTo="
                    () => {
                        this.$router.push({
                            path: './equipHireBiddingApplicationEdit',
                            query: { billid: this.tenderId, seat: 'bidEvaluation' }
                        })
                    }
                "
                :founderId="formData.founderId"
                :state="formData.state"
                :isPrint="false"
            />
            <el-button @click="handleClose">取消</el-button>
        </div>
        <div id="seat" :style="{ height: seatHeight + 'px' }"></div>
    </div>
</template>

<script>
import '@/utils/jquery.scrollTo.min'
// import ComTreeTable from '@/templates/table/treeTable.vue'
// import ComTreeFile from '@/templates/table/treeFile.vue'
// import ComPagination from '@/components/pagination/pagination.vue'
import auditRequest from '@/api/tender/audit.js'
import resultRequest from '@/api/tender/result.js'
import equipmentLeasingRequest from '@/api/tender/equipmentLeasing.js'
import commonRequest from '@/api/tender/common.js'
import ComAttachIndex from '@/components/common/attachIndex'
import ComExaHistory from '@/components/common/exaHistory.vue'
import ComExaButtons from '@/components/common/exaButtons'
import ComShowBiddingButton from '@/pages/bidding/common/showBiddingButton.vue'
import ComInputSelectUnit from '@/pages/bidding/common/inputSelectUnit.vue'
import ComNullify from '@/pages/bidding/common/nullify.vue'
// import ComBidButtons from '@/components/bidding/bidButtons'
import { selectDataClient, openAppClient } from '@/utils/common'
import { mapState, mapMutations } from 'vuex'

export default {
    data () {
        return {
            tabsName: 'baseInfo',
            screenWidth: 0,
            screenHeight: 0,
            lastConHeight: 0,
            clickTabFlag: false, // 如果手动点击时，则不做滚动事件逻辑，只有滚动屏幕时才走滚动事件逻辑
            form: {
                name: '',
                region: '',
                date1: '',
                date2: '',
                delivery: false,
                type: [],
                resource: '',
                desc: ''
            },
            tableData: [],
            value: '',
            textarea: '',
            formData: {},
            test: '',
            selectData: [],
            selectTableColumnAttr: [
                {
                    label: '单据编号',
                    prop: 'billNo'
                },
                {
                    label: '拟招标项目名称',
                    prop: 'tenderName'
                },
                {
                    label: '单据日期',
                    prop: 'gmtCreate'
                },
                {
                    label: '单据机构名称',
                    prop: 'orgName'
                }
            ],
            selectTableColumnWidth: {
                leftWidth: '150',
                rightWidth: '100'
            },
            selectDataPagination: {},
            rules: {
                // tenderApplyNo: {
                //     required: true,
                //     message: '请输入招标编号',
                //     trigger: 'blur'
                // },
                tenderApplyOrgName: {
                    required: true,
                    message: '请输入招标单位',
                    trigger: 'blur'
                },
                projectName: {
                    required: true,
                    message: '请输入拟招标项目名称',
                    trigger: 'blur'
                },
                reportTime: {
                    required: true,
                    message: '请输入登记日期',
                    trigger: 'blur'
                },
                tenderForm: {
                    required: true,
                    message: '请输入采购方式',
                    trigger: 'blur'
                },
                tenderClass: {
                    required: true,
                    message: '请输入招标类型',
                    trigger: 'blur'
                },
                // state: {
                //     required: true,
                //     message: '请输入状态',
                //     trigger: 'blur'
                // },
                evaluationRecord: {
                    required: true,
                    message: '请输入评标记录',
                    trigger: 'blur'
                }
            },
            auditState: {},
            auditParams: {
                billId: this.$route.query.billid,
                billType: 60295,
                freeNextUnitIndex: 0,
                freeNextUser: '',
                isPass: true,
                isShareInAudit: true,
                opinion: ''
            },
            nullifyParams: {
                billId: this.$route.query.billid,
                billType: 60295,
                nullifyCreated: '',
                nullifyCreator: '',
                nullifyCreatorId: '',
                nullifyDescription: '',
                nullifyReason: ''
            },
            candidateList: [],
            candidateListOption: [],
            ruleMessage: '',
            candidateListKey: 0
        }
    },
    computed: {
        ...mapState({
            options: state => state.biddingApplication.dictionaries
        }),
        tenderId () {
            return this.formData.tenderApplyId
        },
        billId () {
            return this.$route.query.billId || this.$route.query.billid
        },
        // 填补底部空白，以使高度够滚动
        seatHeight () {
            return this.screenHeight - 72 - this.lastConHeight
        }
    },
    watch: {
        'auditState.canModify': {
            handler () {
                this.candidateListKey += 1
            }
        }
    },
    components: {
        // ComTreeTable,
        // ComTreeFile,
        // ComPagination
        ComAttachIndex,
        ComExaHistory,
        ComExaButtons,
        ComShowBiddingButton,
        ComInputSelectUnit,
        ComNullify
        // ComBidButtons
    },
    async created () {
        // 查询当前单据信息
        await this.getData()
        // 获取中标单位信息
        await this.resultCandidateListByEntity()
        // 获取单位列表
        this.resultCandidateGetCandidateList()
        // 获取审核按钮状态
        this.getCurrentUnitInfo()
    },
    mounted () {
        // 保存所有tabName
        const arr = ['baseInfo', 'bidWinMan', 'attach', 'auditHistory']
        // 获取最后一个内容区域的高度，计算底部空白
        this.getLastConHeight(arr)
        let $idsTop = []
        window.addEventListener('scroll', () => {
            // 如果手动点击时，则不做滚动事件逻辑，只有滚动屏幕时才走滚动事件逻辑
            if (this.clickTabFlag) {
                return
            }

            if (!$idsTop[$idsTop.length - 1]) {
                $idsTop = arr.map(item => {
                    const itemTop = document.getElementById(item)?.offsetTop
                    return itemTop
                })
            }
            const scrollTop = document.documentElement.scrollTop || document.body.scrollTop
            // 倒序查找
            let curLocal = 0
            for (let len = $idsTop.length, i = len - 1; i >= 0; i--) {
                let item = $idsTop[i]
                if (scrollTop + 1 >= item) {
                    curLocal = i
                    break
                }
            }
            // 设置对应tabName
            this.tabsName = arr[curLocal]
        })

        this.screenWidth = document.documentElement.clientWidth - this.topHeight
        this.screenHeight = document.documentElement.clientHeight - this.topHeight
        window.addEventListener('resize', () => {
            this.screenWidth = document.documentElement.clientWidth - this.topHeight
            this.screenHeight = document.documentElement.clientHeight - this.topHeight
            $idsTop = arr.map(item => {
                const itemTop = document.getElementById(item)?.offsetTop
                return itemTop
            })
        })
    },
    beforeDestroy () {
        this.$notify.closeAll()
    },
    methods: {
        ...mapMutations(['setAuditParams', 'setSelectedInfo']),
        ContractQuery () {
            selectDataClient({
                SelectServiceToken: '/subcontract/thirdParty/getForEquipmentProcurementBidding', // 客户端对应方法名
                IsSingleMode: true, // 是否单选 true 单选 false 多选
                SelectedIDs: [], // 已选中id
                Title: '查看合同签订', // 标题
                InitParamsStr: this.billId
            })
        },
        inputblur (row, val) {
            row[val] = isNaN(parseFloat(row[val])) ? 0 : parseFloat(row[val])
        },
        bidWinRule () {
            const ruleMessageArr = []
            this.candidateList.forEach((item, index) => {
                index
                index += 1
                if (
                    item.firstCandidateId === null &&
                    item.twoCandidateId === null &&
                    item.threeCandidateId === null
                ) {
                    ruleMessageArr.push(`中标候选人${index}必须选择一个单位`)
                }
                if (typeof item.firstAmount !== 'number' && item.firstAmount !== null) {
                    ruleMessageArr.push(`中标候选人${index}第一备选单位投标不含税金额必须为数值`)
                }
                if (typeof item.firstGrade !== 'number' && item.firstGrade !== null) {
                    ruleMessageArr.push(`中标候选人${index}第一备选单位综合得分或价格必须为数值`)
                }
                if (typeof item.twoAmount !== 'number' && item.twoAmount !== null) {
                    ruleMessageArr.push(`中标候选人${index}第二备选单位投标不含税金额必须为数值`)
                }
                if (typeof item.twoGrade !== 'number' && item.twoGrade !== null) {
                    ruleMessageArr.push(`中标候选人${index}第二备选单位综合得分或价格必须为数值`)
                }
                if (typeof item.threeAmount !== 'number' && item.threeAmount !== null) {
                    ruleMessageArr.push(`中标候选人${index}中标单位投标不含税金额必须为数值`)
                }
                if (typeof item.threeGrade !== 'number' && item.threeGrade !== null) {
                    ruleMessageArr.push(`中标候选人${index}中标单位综合得分或价格必须为数值`)
                }
                if (ruleMessageArr.length !== 0) {
                    this.ruleMessage = ruleMessageArr.join('，')
                    this.onChangeTab({
                        name: 'bidWinMan'
                    })
                }
            })
            if (ruleMessageArr.length === 0) {
                this.ruleMessage = ''
                return true
            } else {
                return false
            }
        },
        isFailChange (row) {
            if (row.isFail === 1) {
                this.clientPop(
                    'info',
                    '选择的包件是否流标？确认后将清空中标单位信息，请谨慎操作！',
                    () => {
                        row.firstAmount = 0
                        row.firstCandidate = ''
                        row.firstCandidateId = ''
                        row.firstGrade = 0
                        row.twoAmount = 0
                        row.twoCandidate = ''
                        row.twoCandidateId = ''
                        row.twoGrade = 0
                        row.threeAmount = 0
                        row.threeCandidate = ''
                        row.threeCandidateId = ''
                        row.threeGrade = 0
                    },
                    null,
                    () => {
                        row.isFail = 0
                    }
                )
            } else {
                row.firstCandidateId = null
                row.twoCandidateId = null
                row.threeCandidateId = null
            }
        },
        selectChange (row, val, index, rowIndex) {
            const id = this.candidateListOption[rowIndex].find(item => {
                return item.candidateName === val
            }).candidateId
            console.log('id', id)
            if (index === 1) {
                if (row.twoCandidateId !== id && row.threeCandidateId !== id) {
                    row.firstCandidateId = id
                } else {
                    row.firstCandidate = ''
                    this.clientPop('err', '不能选择同一家单位')
                }
            } else if (index === 2) {
                if (row.firstCandidateId !== id && row.threeCandidateId !== id) {
                    row.twoCandidateId = id
                } else {
                    row.twoCandidate = ''
                    this.clientPop('err', '不能选择同一家单位')
                }
            } else if (index === 3) {
                if (row.twoCandidateId !== id && row.firstCandidateId !== id) {
                    row.threeCandidateId = id
                } else {
                    row.threeCandidate = ''
                    this.clientPop('err', '不能选择同一家单位')
                }
            }
        },
        clientSelect (arg, row) {
            // alert(111)
            row
            if (arg === 'subordinateReferenceOrg') {
                selectDataClient({
                    SelectServiceToken: '/hr/org/getChildrenOrg', // 客户端对应方法名
                    IsSingleMode: true, // 是否单选 true 单选 false 多选
                    SelectedIDs: [], // 已选中id
                    Title: '选择申请单位' // 标题
                }).then(val => {
                    row.subordinateReferenceOrgId = val[0].orgId
                    row.subordinateReferenceOrgName = val[0].orgName
                })
            }
        },
        // 获取审核按钮
        getCurrentUnitInfo () {
            auditRequest.getCurrentUnitInfo(this.auditParams).then(res => {
                this.auditState = res
            })
        },
        // 获取单位列表
        resultCandidateGetCandidateList (name = '') {
            this.candidateList.forEach((item, index) => {
                equipmentLeasingRequest
                    .resultCandidateGetCandidateList({
                        tenderApplyId: this.tenderId,
                        name,
                        packageId: item.packageId
                    })
                    .then(res => {
                        this.candidateListOption[index] = []
                        this.candidateListOption[index] = res
                    })
            })
            // 假数据
            // this.candidateListOption = [
            //     { candidateName: 'a', candidateId: 1 },
            //     { candidateName: 'b', candidateId: 2 },
            //     { candidateName: 'c', candidateId: 3 }
            // ]
        },
        // 获取中标单位信息
        async resultCandidateListByEntity () {
            await equipmentLeasingRequest
                .resultCandidateListByEntity({
                    resultId: this.billId
                })
                .then(res => {
                    this.candidateList = res
                    this.candidateList.forEach(item => {
                        if (item.firstAmount === null) {
                            item.firstAmount = 0
                        }
                        if (item.firstGrade === null) {
                            item.firstGrade = 0
                        }
                        if (item.twoAmount === null) {
                            item.twoAmount = 0
                        }
                        if (item.twoGrade === null) {
                            item.twoGrade = 0
                        }
                        if (item.threeAmount === null) {
                            item.threeAmount = 0
                        }
                        if (item.threeGrade === null) {
                            item.threeGrade = 0
                        }
                    })
                })
        },
        deleteData () {
            this.clientPop('info', '确定要删除吗？数据删除后不可恢复，请谨慎操作！', this.delData)
        },
        onChangeTab (e) {
            const height = $('#' + e.name).offset().top
            $.scrollTo(height - this.topHeight, 500)
            // 如果手动点击时，则不做滚动事件逻辑，只有滚动屏幕时才走滚动事件逻辑
            this.clickTabFlag = true
            // 动画结束后，恢复状态
            setTimeout(() => {
                this.clickTabFlag = false
            }, 600)
        },
        // 获取最后一个内容区域的高度，计算底部空白
        getLastConHeight (arr) {
            let si = setInterval(() => {
                // 因为dom异步加载，通过轮询找到渲染后的dom，获取高度
                if (document.getElementById(arr[length - 1] + 'Con')) {
                    const lastConHeight = document.getElementById(
                        arr[length - 1] + 'Con'
                    )?.offsetHeight
                    this.lastConHeight = lastConHeight
                    clearInterval(si)
                    si = null
                }
            }, 100)
        },
        delData () {
            resultRequest.batchDelete([this.billId]).then(() => {
                const callBack = () => {
                    this.$router.push({
                        path: './equipHireBiddingApplicationEdit',
                        query: { billid: this.tenderId, seat: 'bidEvaluation' }
                    })
                }
                this.clientPop('suc', '删除成功', callBack)
            })
        },
        async getData () {
            await equipmentLeasingRequest.resultGetById({ id: this.billId }).then(res => {
                this.formData = res
            })
        },
        showBidding () {
            if (!this.tenderId) return // 前期需求可切换，现在不需要
            this.$notify.closeAll()
            this.$notify({
                title: '查看招标详情',
                dangerouslyUseHTMLString: true,
                message: `正式环境：客户端打开新页面<br>
                测试环境：手动打开新页面<br>
                <textarea cols="35" rows="10">http://localhost:8080/biddingApplicationShow?tenderId=${this.tenderId}</textarea>
                `,
                duration: 0
            })
            // this.$router.push({
            //     path: './biddingApplicationShow',
            //     query: { tenderId: this.tenderId }
            // })
        },
        // 审核相关操作
        async exas (arg, routeTo) {
            if (arg === 'audit') {
                this.saveAllData(false)
                this.setAuditParams(this.auditParams)
                // 客户端弹窗弹出本地页面
                openAppClient('/exaDialog', '填写审核意见', () => {
                    const auditParams = JSON.parse(localStorage.vuex).auditParams
                    if (auditParams.opinion === '') {
                        this.clientPop('err', '审核意见未填')
                        return
                    }
                    auditRequest.audit(auditParams).then(() => {
                        if (auditParams.isPass) {
                            this.clientPop('suc', '审核成功', routeTo)
                        } else {
                            this.clientPop('suc', '返回修改成功', routeTo)
                        }
                        this.getCurrentUnitInfo()
                        this.getData()
                        this.$refs.ComExaHistory.getAuditHistory()
                    })
                    // this.$refs.ComBidButtons.getButtonState() // 刷新招标按钮
                }, null, null, null, 'small')
            } else if (arg === 'undoAudit') {
                this.clientPop('info', '确定要撤回上一步审核操作吗？', () => {
                    auditRequest.undoAudit(this.auditParams).then(() => {
                        this.clientPop('suc', '撤回成功', routeTo)
                        this.getCurrentUnitInfo()
                        this.getData()
                        this.$refs.ComExaHistory.getAuditHistory()
                    })
                })
            } else if (arg === 'submitCommit') {
                // 保存所有信息
                const promise1 = await this.saveAllData(false)
                //   审核
                const promise2 = auditRequest.commit(this.auditParams)
                Promise.all([promise1, promise2]).then(() => {
                    this.clientPop('suc', '保存并提交成功', routeTo)
                    this.getCurrentUnitInfo()
                    this.getData()
                    this.$refs.ComExaHistory.getAuditHistory()
                })
                // 重置
                this.loadComponent = new Set()
                await this.getData()
                this.$route.query.seat = this.tabsName
                this.ifSeat()
            } else if (arg === 'submit') {
                await this.saveAllData()
                // 重置
                this.loadComponent = new Set()
                this.$route.query.seat = this.tabsName
                this.ifSeat()
            } else if (arg === 'nullify') {
                this.setAuditParams(this.nullifyParams)
                // 客户端弹窗弹出本地页面
                openAppClient('/nullifyDialog', '单据作废原因', () => {
                    const auditParams = JSON.parse(localStorage.vuex).auditParams
                    commonRequest.nullify(auditParams).then(() => {
                        this.clientPop('suc', '作废成功', routeTo)
                        this.getCurrentUnitInfo()
                        this.getData()
                        this.$refs.ComExaHistory.getAuditHistory()
                    })
                }, null, null, null, 'small')
            } else if (arg === 'deleteData') {
                this.clientPop('info', '确定要删除吗？数据删除后不可恢复，请谨慎操作！', () => {
                    equipmentLeasingRequest.resultDelete({ id: this.billId }).then(() => {
                        const callBack = () => {
                            this.$router.push({
                                path: './equipHireBiddingApplicationEdit',
                                query: { billid: this.tenderId, seat: 'bidEvaluation' }
                            })
                        }
                        this.clientPop('suc', '删除成功', callBack)
                    })
                })
            }
        },
        saveAllData (notice = true) {
            return new Promise((resolve, reject) => {
                // 基础信息验证
                this.$refs.ruleForm.validate(async valid => {
                    if (!valid) {
                        this.onChangeTab({ name: 'baseInfo' })
                        reject()
                        return false
                    }
                })
                // 中标单位验证
                if (!this.bidWinRule()) {
                    this.onChangeTab({
                        name: 'bidWinMan'
                    })
                    reject()
                    return false
                }
                // 基本信息保存
                const params = {
                    billId: this.formData.billId,
                    evaluationRecord: this.formData.evaluationRecord,
                    reportTime: this.formData.reportTime
                }
                const promise1 = equipmentLeasingRequest.resultUpdate(params)
                // 中标单位保存
                const promise2 = equipmentLeasingRequest.resultCandidateUpdate(this.candidateList)
                Promise.all([promise1, promise2])
                    .then(() => {
                        resolve()
                        if (notice === false) return
                        this.clientPop('suc', '保存成功')
                    })
                    .catch(() => {
                        reject()
                    })
            })
        },
        // submit () {
        //     resultRequest.update(this.formData).then(() => {
        //         this.clientPop('suc', '保存成功')
        //         // this.$router.push({
        //         //     path: './equipHireBiddingApplicationEdit',
        //         //     query: { billid: this.tenderId, seat: 'bidEvaluation' }
        //         // })
        //     })
        // },
        getNowDate () {
            // 个位数前补0
            const zeroFill = function (num) {
                if (parseInt(num) < 10) {
                    num = '0' + num
                }
                return num
            }
            let nowtime = new Date()
            nowtime =
                zeroFill(nowtime.getFullYear()) +
                '-' +
                zeroFill(nowtime.getMonth() + 1) +
                '-' +
                zeroFill(nowtime.getDate())
            this.$set(this.formData, 'applyTime', nowtime)
        },
        handleClose () {
            this.$router.push({
                path: './equipHireBiddingApplicationEdit',
                query: { billid: this.tenderId, seat: 'bidEvaluation' }
            })
        },
        cellClsNm ({ column }) {
            if (column.label === '') {
                return 'fixed-left'
            }
        },
        cellMouseEnter (row) {
            this.MouseEnterId = row.id
        },
        cellMouseLeave () {
            this.MouseEnterId = 0
        }
    }
}
</script>

<style lang="scss" scoped>
.form {
    margin-top: 10px;
}

.e-table {
    background: #fff;

    /* .top {
    .left {
      padding: 20px;
      padding-top: 0px;
    }
  } */
}

.upload {
    margin: 20px auto;
    display: flex;
    justify-content: center;
    text-align: center;
}

.upload-demo {
    display: flex;
    justify-content: center;
    align-items: center;
}

.ruleMessage {
    margin-bottom: 20px;
    color: red;
}
</style>
